package pl.koziolekweb.gallerygenerator.tools;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class SimpleImageFilter extends FileFilter implements ImageFilter {

	public Boolean isImage(File file) {
		String extension = getExtension(file.getName());
		for (IMAGE_TYPE it : IMAGE_TYPE.values()) {
			if (extension != null)
				if (it.toString().toLowerCase().equals(extension.toLowerCase()))
					return true;
		}
		return false;
	}

	private String getExtension(String name) {
		String[] i = name.split("\\.");
		return i[i.length - 1];
	}

	@Override
	public boolean accept(File f) {
		return isImage(f);
	}

	@Override
	public String getDescription() {
		return "Image";
	}

}
